﻿
using System;

namespace Game.Common
{
    public class PlayerEventArgs : EventArgs 
    {
        readonly GamePlayer _Player;
        
        public PlayerEventArgs(GamePlayer player)
        {
            _Player = player;
        }
        
        public GamePlayer Player
        {
            get { return _Player; }
        }
    }
    
    public class GameTurn
    {
        public event EventHandler<PlayerEventArgs> Changed;
        
        GamePlayer _PlayerWithTurn;
        int _Depth;
        
        public static GameTurn Create()
        {
            return new GameTurn();
        }
        
        public GameTurn CreateChild()
        {
            return new GameTurn(this, _Depth + 1);
        }
        
        GameTurn()
        {
        }
        
        GameTurn(GameTurn turn, int depth)
        {
            _Depth = depth;
            _PlayerWithTurn = turn.PlayerWithTurn;
        }
        
        public GamePlayer PlayerWithTurn
        {
            get { return _PlayerWithTurn; }
            set 
            {
                if (_PlayerWithTurn != value)
                {
                    _PlayerWithTurn=value;
                    DoChanged();
                }
            }
        }
        
        void DoChanged()
        {
            if (Changed != null)
            {
                PlayerEventArgs args = new PlayerEventArgs(_PlayerWithTurn);
                Changed(this, args);
            }
        }
        
        public override string ToString()
        {
            return "<? " + 
                " depth=" + _Depth + 
                " player=" + _PlayerWithTurn + " ?>";
        }

    }
}
